/**
 * Copyright 2011 ArcBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package vn.nichecafe.client.ui.slider;

import java.util.ArrayList;
import java.util.List;

import org.vaadin.gwtgraphics.client.DrawingArea;
import org.vaadin.gwtgraphics.client.shape.Path;

import vn.nichecafe.client.NICHECafeUtils;
import vn.nichecafe.client.ui.UiModule;
import vn.nichecafe.client.ui.slider.content.ContentEnum;
import vn.nichecafe.client.ui.slider.content.MenuPopupContent;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

/**
 * A simple menu that can be reused.
 * <p />
 * Instead of using a static field and {@code GWT.create(Binder.class)} to
 * instantiate the binder we rely on GIN dependency injection. This would
 * facilitate testing if we ever wanted to test this class outside of a
 * {@code GWTTestCase}.
 * <p />
 * Even though this widget contains an {@code @Inject} constructor, it can be
 * used within a UiBinder file. This is made possible by using GWTP's
 * {@link com.google.gwt.uibinder.rebind.GinUiBinderGenerator} and our use of
 * {@code &lt;inherits name="com.google.gwt.uibinder.GinUiBinder" /&gt} in
 * {@code Gwtptabsample.gwt.xml}. This also requires a method returning
 * {@link NicheMenu} in {@link vn.nichecafe.client.gin.ClientGinjector
 * ClientGinjector}. Finally, it is good practice to bind the
 * {@link NicheMenu.Binder} interface as a singleton, which is done in
 * {@link UiModule}.
 * 
 * @author Christian Goudreau
 * @author Philippe Beaudoin
 */
public class NicheMenu extends Composite {

	/**
   */
	public interface Binder extends UiBinder<Widget, NicheMenu> {
	}

	private static final Binder binder = GWT.create(Binder.class);

	@Inject
	public NicheMenu() {
		initWidget(binder.createAndBindUi(this));
		initDrawArea();
	}

	@UiField
	FlowPanel sliderContent;

	private MenuPopupContent menuPopupContent;

	private void initDrawArea() {

		menuPopupContent = new MenuPopupContent();

		DrawingArea area = new DrawingArea(960, 425);
		// Cocktail area
		Path path = createCoffeeArea();
		area.add(path);
		area.bringToFront(path);
		// Vitamin
		path = createVitaminArea();
		area.add(path);
		area.bringToFront(path);
		// Ice blended
		path = createIceblendedArea();
		area.add(path);
		area.bringToFront(path);
		// Special
		path = createSpecialArea();
		area.add(path);
		area.bringToFront(path);
		// Ice cream
		path = createIceCreamArea();
		area.add(path);
		area.bringToFront(path);
		// Soda
		path = createSodaArea();
		area.add(path);
		area.bringToFront(path);
		// Juice
		path = createJuiceArea();
		area.add(path);
		area.bringToFront(path);
		// Tea
		path = createTeaArea();
		area.add(path);
		area.bringToFront(path);
		// Fast food
		path = createFoodArea();
		area.add(path);
		area.bringToFront(path);
		
		// Soft drink
		path = createSoftDrinkArea();
		area.add(path);
		area.bringToFront(path);

		sliderContent.clear();
		sliderContent.add(area);
	}

	private Path createSoftDrinkArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(921, 276));
		listPos.add(new Pos(935, 276));
		listPos.add(new Pos(946, 332));
		listPos.add(new Pos(946, 360));
		listPos.add(new Pos(940, 368));
		listPos.add(new Pos(920, 368));
		listPos.add(new Pos(896, 361));
		listPos.add(new Pos(894, 318));
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.SOFT_DRINK);

		return NICHECafeUtils.createArea(listPos, "softdrink-hover", sliderContent,	menuPopupContent);
	}

	private Path createFoodArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(836, 203));
		listPos.add(new Pos(909, 208));
		listPos.add(new Pos(911, 244));
		listPos.add(new Pos(917, 264));
		listPos.add(new Pos(907, 274));
		listPos.add(new Pos(905, 283));
		listPos.add(new Pos(894, 285));
		listPos.add(new Pos(883, 293));
		listPos.add(new Pos(867, 285));
		listPos.add(new Pos(819, 276));
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.FAST_FOOD);

		return NICHECafeUtils.createArea(listPos, "food-hover", sliderContent,	menuPopupContent);
	}
	
	private Path createTeaArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(733, 190));
		listPos.add(new Pos(743 ,171));
		listPos.add(new Pos(773, 154));
		listPos.add(new Pos(803, 171));
		listPos.add(new Pos(811, 205));
		listPos.add(new Pos(795, 220));
		listPos.add(new Pos(755, 219));
		listPos.add(new Pos(738, 206));
		
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.TEA);

		return NICHECafeUtils.createArea(listPos, "tea-hover", sliderContent,	menuPopupContent);
	}

	private Path createJuiceArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(680, 60));
		listPos.add(new Pos(696, 58));
		listPos.add(new Pos(700, 60));
		listPos.add(new Pos(695, 78));
		listPos.add(new Pos(700, 78));
		listPos.add(new Pos(693, 111));
		listPos.add(new Pos(693, 145));
		listPos.add(new Pos(700, 177));
		listPos.add(new Pos(690, 182));
		listPos.add(new Pos(675, 182));
		listPos.add(new Pos(666, 178));
		listPos.add(new Pos(670, 142));
		listPos.add(new Pos(670, 120));
		listPos.add(new Pos(662, 84));
		listPos.add(new Pos(662, 78));
		listPos.add(new Pos(686, 78));
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.JUICE);

		return NICHECafeUtils.createArea(listPos, "juice-hover", sliderContent,	menuPopupContent);
	}

	private Path createSodaArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(607, 46));
		listPos.add(new Pos(582, 56));
		listPos.add(new Pos(577, 67));
		listPos.add(new Pos(580, 73));
		listPos.add(new Pos(576, 74));
		listPos.add(new Pos(565, 117));
		listPos.add(new Pos(563, 150));
		listPos.add(new Pos(573, 156));
		listPos.add(new Pos(572, 169));
		listPos.add(new Pos(556, 178));
		listPos.add(new Pos(541, 178));
		listPos.add(new Pos(525, 169));
		listPos.add(new Pos(525, 156));
		listPos.add(new Pos(537, 148));
		listPos.add(new Pos(535, 116));
		listPos.add(new Pos(525, 72));
		listPos.add(new Pos(537, 64));
		listPos.add(new Pos(560, 63));
		listPos.add(new Pos(568, 66));
		listPos.add(new Pos(578, 54));
		listPos.add(new Pos(605, 43));
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.SODA);

		return NICHECafeUtils.createArea(listPos, "soda-hover", sliderContent,
				menuPopupContent);
	}

	private Path createIceCreamArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(441, 85));
		listPos.add(new Pos(448, 84));
		listPos.add(new Pos(453, 89));
		listPos.add(new Pos(450, 96));
		listPos.add(new Pos(443, 99));
		listPos.add(new Pos(420, 129));
		listPos.add(new Pos(420, 150));
		listPos.add(new Pos(430, 154));
		listPos.add(new Pos(435, 162));
		listPos.add(new Pos(428, 172));
		listPos.add(new Pos(416, 175));
		listPos.add(new Pos(403, 171));
		listPos.add(new Pos(396, 162));
		listPos.add(new Pos(403, 154));
		listPos.add(new Pos(412, 151));
		listPos.add(new Pos(412, 130));
		listPos.add(new Pos(384, 95));
		listPos.add(new Pos(384, 90));
		listPos.add(new Pos(397, 81));
		listPos.add(new Pos(401, 81));
		listPos.add(new Pos(411, 71));
		listPos.add(new Pos(426, 68));
		listPos.add(new Pos(435, 75));
		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.ICE_CREAM);

		return NICHECafeUtils.createArea(listPos, "icecream-hover",
				sliderContent, menuPopupContent);
	}

	private Path createCoffeeArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(29, 186));
		listPos.add(new Pos(32, 186));
		listPos.add(new Pos(34, 189));
		listPos.add(new Pos(18, 211));
		listPos.add(new Pos(21, 212));
		listPos.add(new Pos(26, 216));
		listPos.add(new Pos(27, 224));
		listPos.add(new Pos(22, 229));
		listPos.add(new Pos(20, 230));
		listPos.add(new Pos(15, 230));
		listPos.add(new Pos(19, 251));
		listPos.add(new Pos(26, 250));
		listPos.add(new Pos(37, 248));
		listPos.add(new Pos(53, 250));
		listPos.add(new Pos(59, 220));
		listPos.add(new Pos(64, 220));
		listPos.add(new Pos(69, 223));
		listPos.add(new Pos(60, 252));
		listPos.add(new Pos(64, 257));
		listPos.add(new Pos(61, 362));
		listPos.add(new Pos(55, 368));
		listPos.add(new Pos(47, 371));
		listPos.add(new Pos(38, 373));
		listPos.add(new Pos(23, 370));
		listPos.add(new Pos(15, 363));
		listPos.add(new Pos(13, 255));
		listPos.add(new Pos(14, 252));
		listPos.add(new Pos(7, 223));
		listPos.add(new Pos(8, 217));
		listPos.add(new Pos(12, 211));

		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.COFFEE);

		return NICHECafeUtils.createArea(listPos, "coffee-hover",
				sliderContent, menuPopupContent);
	}

	private Path createVitaminArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(76, 188));
		listPos.add(new Pos(65, 201));
		listPos.add(new Pos(60, 194));
		listPos.add(new Pos(59, 181));
		listPos.add(new Pos(64, 173));
		listPos.add(new Pos(72, 167));
		listPos.add(new Pos(80, 166));
		listPos.add(new Pos(86, 167));
		listPos.add(new Pos(90, 170));
		listPos.add(new Pos(91, 172));
		listPos.add(new Pos(99, 171));
		listPos.add(new Pos(101, 148));
		listPos.add(new Pos(104, 138));
		listPos.add(new Pos(96, 131));
		listPos.add(new Pos(100, 124));
		listPos.add(new Pos(100, 118));
		listPos.add(new Pos(106, 115));
		listPos.add(new Pos(106, 106));
		listPos.add(new Pos(105, 104));
		listPos.add(new Pos(108, 101));
		listPos.add(new Pos(111, 105));
		listPos.add(new Pos(109, 107));
		listPos.add(new Pos(109, 115));
		listPos.add(new Pos(117, 135));
		listPos.add(new Pos(112, 138));
		listPos.add(new Pos(106, 139));
		listPos.add(new Pos(102, 172));
		listPos.add(new Pos(107, 170));
		listPos.add(new Pos(119, 141));
		listPos.add(new Pos(124, 139));
		listPos.add(new Pos(142, 154));
		listPos.add(new Pos(142, 159));
		listPos.add(new Pos(124, 144));
		listPos.add(new Pos(121, 151));
		listPos.add(new Pos(119, 151));
		listPos.add(new Pos(113, 166));
		listPos.add(new Pos(117, 169));
		listPos.add(new Pos(116, 190));
		listPos.add(new Pos(119, 208));
		listPos.add(new Pos(117, 220));
		listPos.add(new Pos(102, 238));
		listPos.add(new Pos(102, 250));
		listPos.add(new Pos(113, 252));
		listPos.add(new Pos(122, 258));
		listPos.add(new Pos(122, 267));
		listPos.add(new Pos(112, 275));
		listPos.add(new Pos(106, 277));
		listPos.add(new Pos(91, 277));
		listPos.add(new Pos(82, 274));
		listPos.add(new Pos(76, 268));
		listPos.add(new Pos(76, 258));
		listPos.add(new Pos(83, 253));
		listPos.add(new Pos(94, 250));
		listPos.add(new Pos(94, 237));
		listPos.add(new Pos(79, 223));
		listPos.add(new Pos(76, 215));
		listPos.add(new Pos(76, 204));

		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.VITAMIN);

		return NICHECafeUtils.createArea(listPos, "vitamin-hover",
				sliderContent, menuPopupContent);
	}

	private Path createIceblendedArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(182, 125));
		listPos.add(new Pos(186, 121));
		listPos.add(new Pos(192, 119));
		listPos.add(new Pos(201, 118));
		listPos.add(new Pos(216, 121));
		listPos.add(new Pos(222, 126));
		listPos.add(new Pos(219, 143));
		listPos.add(new Pos(219, 150));
		listPos.add(new Pos(221, 160));
		listPos.add(new Pos(221, 166));
		listPos.add(new Pos(220, 170));
		listPos.add(new Pos(204, 186));
		listPos.add(new Pos(204, 196));
		listPos.add(new Pos(219, 201));
		listPos.add(new Pos(222, 206));
		listPos.add(new Pos(222, 213));
		listPos.add(new Pos(207, 222));
		listPos.add(new Pos(194, 222));
		listPos.add(new Pos(184, 219));
		listPos.add(new Pos(178, 213));
		listPos.add(new Pos(178, 204));
		listPos.add(new Pos(187, 198));
		listPos.add(new Pos(196, 196));
		listPos.add(new Pos(196, 185));
		listPos.add(new Pos(185, 175));
		listPos.add(new Pos(181, 165));
		listPos.add(new Pos(183, 153));
		listPos.add(new Pos(184, 141));

		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.ICE_BLENDED);

		return NICHECafeUtils.createArea(listPos, "iceblended-hover",
				sliderContent, menuPopupContent);
	}

	private Path createSpecialArea() {
		List<Pos> listPos = new ArrayList<Pos>();
		listPos.add(new Pos(367, 13));
		listPos.add(new Pos(369, 15));
		listPos.add(new Pos(336, 45));
		listPos.add(new Pos(326, 68));
		listPos.add(new Pos(338, 73));
		listPos.add(new Pos(346, 87));
		listPos.add(new Pos(342, 96));
		listPos.add(new Pos(334, 102));
		listPos.add(new Pos(326, 91));
		listPos.add(new Pos(326, 107));
		listPos.add(new Pos(321, 120));
		listPos.add(new Pos(309, 136));
		listPos.add(new Pos(309, 170));
		listPos.add(new Pos(318, 172));
		listPos.add(new Pos(324, 180));
		listPos.add(new Pos(318, 188));
		listPos.add(new Pos(300, 188));
		listPos.add(new Pos(290, 179));
		listPos.add(new Pos(296, 171));
		listPos.add(new Pos(304, 168));
		listPos.add(new Pos(304, 135));
		listPos.add(new Pos(287, 111));
		listPos.add(new Pos(286, 90));
		listPos.add(new Pos(288, 79));
		listPos.add(new Pos(310, 78));
		listPos.add(new Pos(310, 71));
		listPos.add(new Pos(322, 67));
		listPos.add(new Pos(334, 41));
		listPos.add(new Pos(334, 29));
		listPos.add(new Pos(340, 34));
		listPos.add(new Pos(346, 27));
		listPos.add(new Pos(344, 24));
		listPos.add(new Pos(349, 21));
		listPos.add(new Pos(325, 26));

		menuPopupContent = new MenuPopupContent();

		menuPopupContent.loadContent(ContentEnum.SPECIAL_DRINK);

		return NICHECafeUtils.createArea(listPos, "special-hover",
				sliderContent, menuPopupContent);
	}
}